package com.baosight.risk.web.fltd;

import com.alibaba.fastjson.JSON;
import com.baosight.risk.api.fltd.FltdPressService;
import com.baosight.risk.base.controller.BaseController;
import com.baosight.risk.common.result.AjaxResult;
import com.baosight.risk.service.fltd.entity.FltdPress;
import com.baosight.risk.service.riri.entity.RiriDutyUser;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.ws.rs.core.MediaType;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 作者： lishaoqing
 * 时间： 2019年09月25日
 * 描述： FltdPressController
 * 版本: v1.0
 */
@Api(value = "工作流催办", description = "工作流催办", produces = MediaType.APPLICATION_JSON)
@Slf4j
@RestController
@RequestMapping("/fltd/press")
public class FltdPressController extends BaseController {

    @Autowired
    private FltdPressService fltdPressService;

    @ApiOperation("新增催办配置")
    @PostMapping("add")
    public AjaxResult add(@RequestBody FltdPress urgent) {
        return AjaxResult.success("操作成功", fltdPressService.insert(urgent));
    }

    @ApiOperation("查询催办历史")
    @GetMapping("list")
    public AjaxResult list(String procGuid) {
        startPage("press_date","desc");
        return getResultPage(fltdPressService.queryAll(procGuid));
    }

    @ApiOperation("新增一条催办")
    @PostMapping("urgent")
    public AjaxResult createUrgent(@RequestBody FltdPress fltdPress)  throws Exception{
        fltdPressService.createUrgent(fltdPress);
        return AjaxResult.success();
    }

    @ApiOperation("批量新增催办")
    @PostMapping("urgents")
    public AjaxResult createUrgent(@RequestBody Map<String ,Object> map)  throws Exception{
        String str1 = (String) map.get("one");
        String str2 = (String) map.get("two");
        List<Map> list = (List<Map>) map.get("list");


        fltdPressService.createUrgents(list,str1,str2);
        return AjaxResult.success();
    }

    @ApiOperation("专家组批量催办")
    @PostMapping("expertUrgent")
    public AjaxResult expertUrgent(@RequestBody Map<String ,Object> map)  throws Exception{
        //获取id
        String id = (String) map.get("id");
        //根据id去



        String str1 = "";
        String str2 = "";
        //待传进被催办人userCode
        if(!map.containsKey("one")){
            str1 = "专家组终审催办";
        }else {
            str1 = (String) map.get("one");
        }
        if(!map.containsKey("two")){
            str2 = "专家组终审催办";
        }else {
            str2 = (String) map.get("two");
        }

        List<Map> list = (List<Map>) map.get("list");

        ArrayList<FltdPress> fltdPresses = new ArrayList<>();

        for (Map map1:list){
            RiriDutyUser user = JSON.parseObject(JSON.toJSONString(map1), RiriDutyUser.class);
            FltdPress fltdPress = new FltdPress();
//            不确定是否开放
//            fltdPress.setCurrUserCode();
//            fltdPress.setCurrUserName();

        }

        fltdPressService.expertUrgent(list,str1,str2);
        return AjaxResult.success();
    }

    @ApiOperation("批量新增结题催办")
    @PostMapping("finishUrgents")
    public AjaxResult finishUrgents(@RequestBody Map<String ,Object> map)  throws Exception{
        String str1 = (String) map.get("one");
        String str2 = (String) map.get("two");
        List<Map> list = (List<Map>) map.get("list");


        fltdPressService.createFinishUrgents(list,str1,str2);
        return AjaxResult.success();
    }


}
